package com.yuantu.judiciary.manager.factory;


import cn.hutool.extra.spring.SpringUtil;
import com.yuantu.judiciary.dao.ISysPlatformOperateLogDao;
import com.yuantu.judiciary.model.domain.SysOperLogDO;
import com.yuantu.judiciary.model.domain.SysPlatformOperateLogDO;
import com.yuantu.judiciary.service.ISysOperLogService;
import com.yuantu.judiciary.service.ISysPlatformOperateLogService;
import com.yuantu.judiciary.utils.ip.AddressUtil;

import java.util.TimerTask;

/**
 * 异步工厂（产生任务用）
 *
 * @author ruoyi
 */
public class AsyncFactory {

    /**
     * 操作日志记录
     *
     * @param operLog 操作日志信息
     * @return 任务task
     */
    public static TimerTask recordOper(final SysOperLogDO operLog) {
        return new TimerTask() {
            @Override
            public void run() {
                // 远程查询操作地点
                operLog.setOperLocation(AddressUtil.getRealAddressByIP(operLog.getOperIp()));
                SpringUtil.getBean(ISysOperLogService.class).addOperLog(operLog);
            }
        };
    }

    public static TimerTask recordSysPlatformOper(final SysPlatformOperateLogDO operLog) {
        return new TimerTask() {
            @Override
            public void run() {
                SpringUtil.getBean(ISysPlatformOperateLogService.class).addSysPlatformOperateLog(operLog);
            }
        };
    }

}
